package cookie;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 演示 Cookie path 的作用，当浏览器路径包含了 cookie path 时，该 cookie 会被返回给浏览器
 */
public class Path extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Cookie cookie1 = new Cookie("/cookie", "/cookie");
        cookie1.setPath("/cookie");

        Cookie cookie2 = new Cookie("/cookie/path", "/cookie/path");
        cookie2.setPath("/cookie/path");

        Cookie cookie3 = new Cookie("default", "default");

        resp.addCookie(cookie1);
        resp.addCookie(cookie2);
        resp.addCookie(cookie3);
    }
}
